package com.gnar.dis;

import android.graphics.Bitmap;

public class Ship extends Sprite {

	private float mLastT;
	private float mLastDeltaT;
	private float sin;

	public Ship(Bitmap bitmap, float startPosX, float startPosY) {
		super(bitmap, startPosX, startPosY);
		
		spriteType = type.SHIP;
	}

	@Override
	public void update(EventHandler mEventHandler) {
		
		// Get Acceleration
		// TODO: Adding force due to accellerometer should use AddForce(p) on the object
		// where p is a Vector representing the accelerometer movement. -CP
		
		mAccelX = mAccelX + mEventHandler.getSensorX();
		mAccelY = mEventHandler.getSensorY();

		// Change position
		mPosX = mPosX + mAccelX * 0.1f;
		mPosY = (float) (mPosY + Math.sin(sin));
		
		if (mPosX < 0) {
			mPosX = 1;
			mAccelX = 0;
		}
		if (mPosX > 800 - mImage.getWidth()) {
			mPosX = 800 - mImage.getWidth();
			mAccelX = 0;
		}
		mRect.set((int)mPosX, (int)mPosY, 
			  (int)mPosX + (int)mImage.getWidth(), 
			  (int)mPosY + (int)mImage.getHeight());
		
		// Set Last Position
		mLastPosX = mPosX;
		mLastPosY = mPosY;
		sin += 0.05;
	}
}
